from django.shortcuts import render,redirect 
from django.urls import reverse
from django.http import HttpResponse as response
from App.models import *
# Create your views here.
def index(request):
    return render(request, 'index.html')

def user_list(request):
    users= User.objects.all()

    return render(request, 'user_list.html' ,{'users':users} )

def user_detail(request,uid):
    print(uid)
    user = User.objects.get(pk=uid)
    return render(request, 'user_detail.html', {'user':user})

def user_ab_test(request,a,b):
    return response(f"a:{a}-b:{b}")

def user_ba_test(request,bttt,a):
    return response(f"a:{a}-b:{bttt}")

# 重定向
def my_redirect(request):
    # return redirect('http://www.baidu.com')
    # return redirect('/user/userlist/')
    # return redirect('/user/userlist/2/')
    # 反向解析
    # 位置传参
    # return redirect(reverse('App:userab',args=[222,'abc']))
    # 关键字传参
    return redirect(reverse('App:userba',kwargs={'bttt':'abeji34iu9zvj','a':3456789}))
